diff options
author | Étienne Loks <etienne.loks@peacefrogs.net> | 2012-08-27 19:53:17 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2012-08-27 19:53:17 +0200 |
commit | 427a05d328fccc99a9339dbc6c933281eaaaa3b9 (patch) | |
tree | b0c7cbf440ff5b29e71074a35e542b1aaffa8dc4 | |
parent | cfd0b613480a841bb82c67f0354b44b8d1f5063c (diff) | |
download | Chimère - projet Saclay-427a05d328fccc99a9339dbc6c933281eaaaa3b9.tar.bz2 Chimère - projet Saclay-427a05d328fccc99a9339dbc6c933281eaaaa3b9.zip |
Work on form panel
-rw-r--r-- | forms.py | 38 | ||||
-rw-r--r-- | local_settings.py.sample | 2 | ||||
-rw-r--r-- | static/saclay/css/styles-saclay.css | 39 | ||||
-rw-r--r-- | static/saclay/js/interface.js | 40 | ||||
-rw-r--r-- | templates/chimere/edit.html | 115 | ||||
-rw-r--r-- | templates/chimere/main_map.html | 40 | ||||
-rw-r--r-- | urls.py | 4 | ||||
-rw-r--r-- | views.py | 67 |
8 files changed, 332 insertions, 13 deletions
diff --git a/forms.py b/forms.py new file mode 100644 index 0000000..77e9648 --- /dev/null +++ b/forms.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (C) 2012 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet> + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# See the file COPYING for details. + +""" +Forms +""" +from django import forms +from django.utils.translation import ugettext as _ + +from chimere.models import SubCategory +from chimere.forms import MarkerForm as BaseMarkerForm +from chimere.widgets import TextareaWidget + +class MarkerForm(BaseMarkerForm): + categories = forms.ChoiceField(choices=[], widget=forms.Select) + description = forms.CharField(widget=TextareaWidget) + + def __init__(self, *args, **kwargs): + super(MarkerForm, self).__init__(*args, **kwargs) + self.fields['categories'].widget.choices = [('', _(u"Select"))] + \ + SubCategory.getAvailableTuples() + diff --git a/local_settings.py.sample b/local_settings.py.sample index 9ccd41d..4b17152 100644 --- a/local_settings.py.sample +++ b/local_settings.py.sample @@ -26,4 +26,4 @@ DATABASES = { }, } -ROOT_URLCONF = 'example_project.urls' +ROOT_URLCONF = 'chimere_saclay.urls' diff --git a/static/saclay/css/styles-saclay.css b/static/saclay/css/styles-saclay.css index f7f8f93..bd5911c 100644 --- a/static/saclay/css/styles-saclay.css +++ b/static/saclay/css/styles-saclay.css @@ -9,6 +9,11 @@ html, h1, h2, color:#444; } +/* light */ +.notice{ + color:#999; +} + /* activated */ .action li.ui-state-active{ color:#fff; @@ -16,12 +21,12 @@ html, h1, h2, /* strong */ -h4{ +h4, legend{ color:#000; } /* links */ -a, a:link, a:visited, legend, +a, a:link, a:visited, #footer .map-footer a, #footer .map-footer a:link, #footer .map-footer a:visited, .detail_footer a, caption{ @@ -103,6 +108,21 @@ h4{ font-weight:bold; } +fieldset{ + border-width:0; +} + +legend{ + font-size:1.4em; + width:100%; + border-bottom:1px solid; + padding:0 0.1em 0.6em 0.1em; +} + +.notice{ + font-size:0.8em; +} + #content{ border:none; padding:0; @@ -149,7 +169,7 @@ ul#action-2 { display:block; float: left; margin:0; - padding:5px 22px; + padding:5px; height:22px; } @@ -159,8 +179,7 @@ ul.action li{ } .action li:hover, -.action li label:hover -{ +.action li label:hover{ cursor:pointer; background-color:#ccc; } @@ -168,7 +187,7 @@ ul.action li{ ul#action{ border-right-width:1px; border-right-style:solid; - width:238px; + width:272px; } #panel #categories{ @@ -206,6 +225,10 @@ ul#action{ height:auto; } +#edit-actions{ + display:none; +} + div#sidebar{ z-index:7; width:281px; @@ -419,6 +442,10 @@ div.cloud h4{ padding:0 1em; } +#frm-edit-route, #frm-edit-event{ + display:none; +} + .olControlSimplePanZoom #slider, .olControlSimplePanZoom #zoomin, .olControlSimplePanZoom #zoomout, diff --git a/static/saclay/js/interface.js b/static/saclay/js/interface.js new file mode 100644 index 0000000..5a1c061 --- /dev/null +++ b/static/saclay/js/interface.js @@ -0,0 +1,40 @@ +$(function(){ + var _frm_editmarker_initialized; + var _frm_editroute_initialized; + var _frm_editevent_initialized; + + var update_editmarker = function(){ + $.ajax({url: edit_url, + dataType: "html", + success: function (data) { + $('#frm-edit-marker').html(data); + }, + error: function (data) { + $('#frm-edit-marker').html("<p class='warning'>"+ + default_error_message+"</p>"); + } + }); + }; + + $("#action-carte").click(function(){ + $('#action-participate').removeClass('ui-state-active'); + $('#action-carte').addClass('ui-state-active'); + $('#edit-actions').hide(); + $('#map-actions').show(); + $('#edit-panel').hide(); + $('#map-panel').show(); + }); + + $("#action-participate").click(function(){ + $('#action-carte').removeClass('ui-state-active'); + $('#action-participate').addClass('ui-state-active'); + $('#map-actions').hide(); + $('#edit-actions').show(); + $('#map-panel').hide(); + $('#edit-panel').show(); + // if the default is initialized the other are not + if (!_frm_editmarker_initialized){ + update_editmarker(); + } + }); +}); diff --git a/templates/chimere/edit.html b/templates/chimere/edit.html new file mode 100644 index 0000000..a28f3ed --- /dev/null +++ b/templates/chimere/edit.html @@ -0,0 +1,115 @@ +{% load i18n chimere_tags adminmedia inline_formset%} + {% if submited %}{% submited %}{% endif %} + <fieldset class='edit'> + <legend>{% trans "Add a location" %}</legend> + <div class='notice'> + Consigne d'utilisation : Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc eu luctus ipsum. Donec vel urna a turpis consectetur consectetur. Vestibulum ut enim vel odio porta vulputate. + </div> + {% if error_message %}<fieldset class='edit errorlist'> + <legend>{% trans "Error" %}</legend> + <p>{{ error_message }}</p> + {% endif %}</fieldset> + <form enctype="multipart/form-data" method='post' action='.'> + {% csrf_token %} + {%if form.point.errors %}<ul class="errorlist"><li>{% trans "Select a location for this new site" %}</li></ul>{%endif%} + {% comment %}{{point_widget}}{% endcomment%} + <div class="fieldWrapper"> + <label for="id_name">{% trans "Name of the location"%} *</label> + {% if form.name.errors %}<div class='errors'>{{ form.name.errors }}</div>{% endif %} + {{ form.name }} + </div> + <div class="fieldWrapper"> + <label for="id_subcategory">{% trans "Category" %} *</label> + {% if form.categories.errors %}<div class='errors'>{{ form.categories.errors }}</div>{% endif %} + {{ form.categories }} + </div> + {% for field in form %} + {% for property in properties %} + {% ifequal field.name property.getNamedId %} + <div class="fieldWrapper"> + <label for="id_{{field.name}}">{% trans field.label %}{% if property.mandatory %} *{% endif %}</label> + {% if field.errors %}<div class='errors'>{{ field.errors }}</div>{% endif %} + {{ field }} + </div> + {%endifequal%} + {%endfor%} + {%endfor%} + <div class="fieldWrapper"> + <label for="id_description">{% trans "Description" %}</label> + {{ form.description.errors }} + {{ form.description }} + <p class="help">{{ form.description.help_text }}</p> + </div> + + <p>* {% trans "indicates a mandatory field" %}</p> + {% inline_formset "Multimedia files" formset_multi %} + {% inline_formset "Picture files" formset_picture %} + + {% if filtered_properties %} + <script type='text/javascript'> + var cat_filters = new Array(); + var cat_to_hide = new Array(); + {% for property in filtered_properties %} + cat_to_hide.push('#id_{{property.getNamedId}}'); + {% for subcat in property.subcategories.all %} + if(!cat_filters['{{subcat.id}}']) cat_filters['{{subcat.id}}'] = new Array(); + cat_filters['{{subcat.id}}'].push('#id_{{property.getNamedId}}'); + {% endfor %} + {% endfor %} + $('#id_categories').change(function(){ + for (idx in cat_to_hide){ + $(cat_to_hide[idx]).parent().hide(); + } + var vals = $(this).val(); + for (val_id in vals){ + var val = vals[val_id]; + for (ids in cat_filters[val]){ + $(cat_filters[val][ids]).parent().show(); + } + } + }); + $('#id_categories').change(); + </script> + {% endif %} + <div class='personalform'> + <h3>{% trans "Personal information"%}</h3> + <div class='warning'> + {% trans "This fields are not mandatory. If you provided them they not will be made public and they will only used to join you for this project."%} + </div> + <div class="fieldWrapper"> + <label for="id_submiter_name">{% trans "Your name or nickname"%}</label> + {% if form.submiter_name.errors %}<div class='errors'>{{ form.submiter_name.errors }}</div>{% endif %} + {{ form.submiter_name }} + </div> + <div class="fieldWrapper"> + <label for="id_submiter_email">{% trans "Your email"%}</label> + {% if form.submiter_email.errors %}<div class='errors'>{{ form.submiter_email.errors }}</div>{% endif %} + {{ form.submiter_email }} + </div> + <div class="fieldWrapper"> + <label for="id_submiter_comment">{% trans "Comments about your submission"%}</label> + {% if form.submiter_comment.errors %}<div class='errors'>{{ form.submiter_comment.errors }}</div>{% endif %} + {{ form.submiter_comment }} + </div> + </div> + <div id='upload_in_progress'> + <p>{% trans "Upload in progress. Please wait..." %}</p> + <p><img src='{{STATIC_URL}}chimere/img/ajax-loader.gif'/></p> + </div> + <script text='text/javascript'> + $( "#upload_in_progress" ).dialog({ + modal: true, + resizable:false, + height:110, + autoOpen:false + } + ); + $(".ui-dialog-titlebar").hide(); + function displayProgress(){ + $("#upload_in_progress").dialog('open'); + return true; + } + </script> + <p><input type='submit' onclick='saveExtent();displayProgress();' value="{% trans 'Propose'%}"/></p> + </form> + </fieldset> diff --git a/templates/chimere/main_map.html b/templates/chimere/main_map.html index f4b10f4..e6eefba 100644 --- a/templates/chimere/main_map.html +++ b/templates/chimere/main_map.html @@ -5,8 +5,15 @@ {% head_jquery %} {% head_chimere %} {% head_jme %} +{% head_form %} <script src="{{ STATIC_URL }}chimere/js/jquery.chimere.js"></script> <script src="{{ STATIC_URL }}saclay/js/SaclayCloud.js"></script> + +<script type='text/javascript' language='javascript'> + var default_error_message = "{% trans "Error while loading the page... Refresh the page. If the problem persist contact the webmaster." %}"; + var edit_url = {% url edit %}; +</script> +<script src="{{ STATIC_URL }}saclay/js/interface.js"></script> {% endblock %} {% block message_edit %}{% endblock %} {% block sidebar %} @@ -14,7 +21,7 @@ < </div> <div id='action-panel'> - <ul class='action'> + <ul id='map-actions' class='action'> <li id='action-categories' class='ui-widget ui-button ui-state-default ui-corner-all ui-state-active'> <label>{% trans "Categories" %}</label> </li> @@ -22,14 +29,35 @@ <label>{% trans "Routing" %}</label> </li> </ul> + <ul id='edit-actions' class='action'> + <li id='action-edit-marker' class='ui-widget ui-button ui-state-default ui-corner-all ui-state-active'> + <label>{% trans "Location" %}</label> + </li> + <li id='action-edit-route' class='ui-widget ui-button ui-state-default ui-corner-all'> + <label>{% trans "Wander" %}</label> + </li> + <li id='action-edit-event' class='ui-widget ui-button ui-state-default ui-corner-all'> + <label>{% trans "Event" %}</label> + </li> + </ul> </div> <div id='panel'> - <form method='post' name='frm_categories' id='frm_categories'> - <div id='categories'> - {# Categories are displayed in JS #} + <div id='map-panel'> + <form method='post' name='frm_categories' id='frm_categories'> + <div id='categories'> + {# Categories are displayed in JS #} + </div> + </form> + {% routing %} + </div> + <div id='edit-panel'> + <div id='frm-edit-marker'> + </div> + <div id='frm-edit-route'> + </div> + <div id='frm-edit-event'> </div> - </form> - {% routing %} + </div> </div> {% endblock %} {% block content %} @@ -33,6 +33,10 @@ urlpatterns += staticfiles_urlpatterns() urlpatterns += patterns('', (r'^admin/doc/', include('django.contrib.admindocs.urls')), (r'^admin/', include(admin.site.urls)), + url(r'^(?P<area_name>[a-zA-Z0-9_-]+/)?edit/$', 'views.edit', + name="edit"), + url(r'^(?P<area_name>[a-zA-Z0-9_-]+/)?edit/(?P<item_id>\w+)/(?P<submited>\w+)?$', + 'views.edit', name="edit-item"), url(r'^', include('chimere.urls', namespace="chimere")), ) diff --git a/views.py b/views.py new file mode 100644 index 0000000..4bc5bc6 --- /dev/null +++ b/views.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (C) 2012 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet> + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# See the file COPYING for details. + +from django.conf import settings +from django.shortcuts import render_to_response +from django.template import RequestContext + +from forms import MarkerForm + +from chimere.actions import actions +from chimere.models import Marker, PropertyModel +from chimere.views import get_edit_page + +get_edit_marker = get_edit_page('edit', Marker, MarkerForm) + +def edit(request, area_name="", item_id=None, submited=False): + """ + Edition page + """ + response, values, sub_categories = get_edit_marker(request, area_name, + item_id, ['M', 'B']) + if response: + return response + item_id, init_item, response_dct, form, formset_multi, formset_picture = \ + values + # get the "manualy" declared_fields. Ie: properties + declared_fields = form.declared_fields.keys() + declared_fields = PropertyModel.objects.filter(available=True).all() + filtered_properties = PropertyModel.objects.filter(available=True, + subcategories__id__isnull=False).all() + response_dct.update({ + 'actions':actions, + 'action_selected':('contribute', 'edit'), + 'map_layer':settings.CHIMERE_DEFAULT_MAP_LAYER, + 'form':form, + 'formset_multi':formset_multi, + 'formset_picture':formset_picture, + 'dated':settings.CHIMERE_DAYS_BEFORE_EVENT, + 'extra_head':form.media, + 'marker_id':item_id, + 'sub_categories':sub_categories, + 'point_widget':'', + 'properties':declared_fields, + 'filtered_properties':filtered_properties, + 'submited':submited + }) + # manualy populate the custom widget + if 'subcategory' in form.data and form.data['subcategory']: + response_dct['current_category'] = int(form.data['subcategory']) + return render_to_response('chimere/edit.html', response_dct, + context_instance=RequestContext(request)) |